{js:artTemplate}
<script type='text/javascript' src='{theme:javascript/artTemplate/area_select.js}'></script>

<section>
    <div class="pending-detial">

    <div class="panel panel-default">
		  <div class="panel-heading">
				<h3 class="panel-title">地址管理</h3>
		  </div>

		  <div class="panel-body">
		    <ul class="list-group">
		    
		{foreach:items=$this->address}
		    	<li class="list-group-item ">
		    	<table class="table table-bordered table-hover">
				
					<tbody>
						<tr>
							<td>联系人</td><td>{$item['accept_name']}</td>
						</tr>
						<tr>
							<td>省份地区</td><td>{$this->areas[$item['province']]}{$this->areas[$item['city']]}{$this->areas[$item['area']]}</td>
						</tr>
						<tr>
							<td>详细地址</td><td>{$item['address']}</td>
						</tr>

						<tr>
							<td>手机</td><td>{$item['mobile']}</td>
						</tr>


						<tr>
							<td>座机</td><td>{$item['telphone']}</td>
						</tr>

						<tr>
							<td>邮编</td><td>{$item['zip']}</td>
						</tr>

						<tr>
							<td>默认地址</td><td>{echo:$item['default'] == 1 ? '是':'否'}</td>
						</tr>


	<tr><td>操作</td><td>

	<div class="btn-group">
				<button type='button' style="width:62px" class="btn btn-default" onclick='form_back({echo:JSON::encode($item)})' />修改</button>
				<button type='button'  style="width:62px" class="btn btn-default" onclick="delModel({link:'{url:/ucenter/address_del/id/$item[id]}'});" value='删除' />删除</button>
				{if:$item['default']==1}
				<button type='button' style="width:62px" class="btn btn-default" onclick="window.location.href='{url:/ucenter/address_default/id/$item[id]/default/0}'"  />取消默认</button>
				{else:}
				<button type='button' style="width:62px" class="btn btn-default" onclick="window.location.href='{url:/ucenter/address_default/id/$item[id]/default/1}'" />设为默认</button>
				{/if}

	</div>
				</td>
		</tr>



						
				

					</tbody>
				</table></li>
				
	  {/foreach}

			</ul>
		  </div>

		
		  
	
			  <div style="padding:10px">
				<h4>地址修改</h4>

				<form action="{url:/ucenter/address_edit}" method="POST" class="form-inline" role="form" name='form'>
				<input name='id' type='hidden' value='' />
				
					<div class="form-group">
						<label class="sr-only" for="">label</label>
						<input type="text" name='accept_name' class="form-control" id="" placeholder="收货人姓名">
					</div>

		<div class="form-group">
			<label for="input" class="col-sm-2 control-label">所在地区:</label>
			<div class="col-sm-2">
				<select name="province" child="city,area" onchange="areaChangeCallback(this);"  class="form-control" >
					
				</select>
			</div>
			<div class="col-sm-2">
				<select name="city" child="area" parent="province" onchange="areaChangeCallback(this);"  class="form-control" >
					
				</select>
			</div>
			<div class="col-sm-2">
				<select name="area" parent="city"  class="form-control" >
					
				</select>
			</div>
		</div>

					<div class="form-group">
						<label class="sr-only" for="">label</label>
						<input type="text" name='address'   class="form-control" id="" placeholder="街道地区">
					</div>

					<div class="form-group">
						<label class="sr-only" for="">label</label>
						<input type="text" name='zip'    class="form-control" id="" placeholder="邮政编码">
					</div>

					<div class="form-group">
						<label class="sr-only" for="">label</label>
						<input type="text" name='mobile'   class="form-control" id="" placeholder="电话号码">
					</div>

					<div class="form-group">
						<label class="sr-only" for="">label</label>
						<input type="text" name='address'   class="form-control" id="" placeholder="邮政编码">
					</div>


					<div class="form-group">
					<label  for="">设为默认：</label>
				<input name='default' type='checkbox' value='1'>
					</div>
				
					
				
					<button type="submit" class="btn btn-primary">保存</button>
				</form>
		  </div>
		
	</div>


    	
	</div>
</section>

<script type='text/javascript'>
//DOM加载完毕
$(function(){
	//初始化地域联动
	template.compile("areaTemplate",areaTemplate);

	createAreaSelect('province',0,'');
});

/**
 * 生成地域js联动下拉框
 * @param name
 * @param parent_id
 * @param select_id
 */
function createAreaSelect(name,parent_id,select_id)
{
	//生成地区
	$.getJSON("{url:/block/area_child}",{"aid":parent_id,"random":Math.random()},function(json)
	{
		$('[name="'+name+'"]').html(template.render('areaTemplate',{"select_id":select_id,"data":json}));
	});
}

//修改地址
function form_back(obj)
{
    //自动填充表单
	var form = new Form('form');
	form.init(obj);

	createAreaSelect('province',0,obj.province);
	createAreaSelect('city',obj.province,obj.city);
	createAreaSelect('area',obj.city,obj.area);
}

//清空表单
function form_empty()
{
	var formInstance = new Form('form');
	$('form[name="form"] input[name]').each(function(){
		formInstance.setValue(this.name,'');
	});

	createAreaSelect('province',0,'');
	$('select[name="city"]').empty();
	$('select[name="area"]').empty();
}
</script>
